#!/usr/bin/python

""" CLASS/MODULE:
    Purpose:
"""
__author__ = 'liwei79@gmail.com'

from util import *

from RTL.RTLReg import *
from RTL.RTLBlock import *
from RTL.RTLRoutine import *
from RTL.RTLProgram import *

class CGAux:
    def __init__(self, cg):
        self.resetTempRegs()
        self.resetBBs()
        self.resetRouts()
        self.routIdIncr = ROUT_START_ID
        self.cg = cg
        self.initProgram()

    def test(self):
        print "Hello"
        print self.routIdIncr

    def initProgram(self):
        self.prog = RTLProgram()

    def getProgram(self):
        return self.prog

    ###allocate new register
    def newTempReg(self):
        temp = RTLReg(self.currentTempReg)
        self.currentTempReg = self.currentTempReg + 1
        return temp

    def resetTempRegs(self):
        self.currentTempReg = TEMP_REG_START

    ###allocate new bb
    def newBB(self):
        bb = RTLBlock(self.currentBB)
        self.currentBB = self.currentBB + 1
        return bb

    def resetBBs(self):
        self.currentBB = BB_START_ID

    #FACTORIES

    ###for ROUT
    def resetRouts(self):
        self.routIdIncr = ROUT_START_ID

    def getCurrentRt(self):
        return self.currentRout

    def genRoutStart(self, name):
        head = CodeRout(name, OpndLst([]))
        self.currentRout = RTLRoutine(head, self.routIdIncr)
        self.prog.addRout(self.currentRout)
        DBG("Create new routine_%d" % self.routIdIncr)
        return self.currentRout

    def genRoutEnd(self):
        self.currentRout = 0
        self.routIdIncr = self.routIdIncr + 1

    def genRoutAppendParam(self, parm):
        parmLst = self.currentRout.headCode.getOpndLst()
        parmLst.append(parm)

    def genBop(self, lhs, op1, op2):
        assert(0)

    def genUop(self, lhs, op1, op2):
        assert(0)

    def genAssign(self, lhs, rhs):
        assert(0)

    def genIf(self, cond, body):
        assert(0)

    def genIfElse(self, cond, if_body, else_body):
        assert(0)

    def genLoop(self, cond, loop_body): 
        assert(0)

if __name__ == "__main__":
    pass
